package com.nginx.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nginx.web.domain.ServerInfoQo;
import com.nginx.web.entity.ServerInfo;
import com.nginx.web.mapper.ServerInfoMapper;
import com.nginx.web.service.ServerInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2025-01-15
 */
@Service
public class ServerInfoServiceImpl extends ServiceImpl<ServerInfoMapper, ServerInfo> implements ServerInfoService {

    public Page<ServerInfo> listServerInfo(ServerInfoQo serverInfoQo) {
        Page<ServerInfo> page = new Page<>(serverInfoQo.getPage() , serverInfoQo.getLimit());
        LambdaQueryWrapper<ServerInfo> wrapper = Wrappers.lambdaQuery(ServerInfo.class);
        if(serverInfoQo.getConfInfoId() != null){
            wrapper.eq(ServerInfo::getConfInfoId , serverInfoQo.getConfInfoId());
        }
        if(serverInfoQo.getPort() != null){
            wrapper.like(ServerInfo::getListen , serverInfoQo.getPort());
        }
        if(serverInfoQo.getIsEnable() != null){
            wrapper.like(ServerInfo::getIsEnable , serverInfoQo.getIsEnable());
        }
        page(page , wrapper);
        return page;
    }

    public void updateServerInfo(ServerInfo serverInfo) {
        updateById(serverInfo);
    }
}
